<?php
namespace App;

trait ReturnMsg
{
    /**
     * @param array $data
     * @return \Illuminate\Http\JsonResponse
     */
    public function success($data = [])
    {
        list($code , $msg) = Config('constants.SUCCESS');
        $res = [
            'status'=>true,
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];

        return response()->json($res);
    }

    /**
     * @param string $code
     * @param string $msg
     * @param array $data
     * @return \Illuminate\Http\JsonResponse
     */
    public function fail(string $code = "ERROR", string $msg = '' , array $data = [])
    {
        list($code , $codeMsg) = Config('constants.' . $code);
        $res = [
            'status'=>false,
            'code' => $code,
            'msg' => $msg ? $msg : $codeMsg,
            'data' => $data
        ];

        return response()->json($res);

    }
}